/*     */ package com.zimbra.cs.octosync;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.io.OutputStream;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PatchManifest
/*     */ {
/*     */   private Map<Reference, Long> references;
/*     */   
/*     */   private final class Reference
/*     */   {
/*     */     int fileId;
/*     */     int version;
/*     */     
/*     */     public Reference(int fileId, int version)
/*     */     {
/*  40 */       this.fileId = fileId;
/*  41 */       this.version = version;
/*     */     }
/*     */     
/*     */ 
/*     */     public boolean equals(Object obj)
/*     */     {
/*  47 */       if ((obj instanceof Reference)) {
/*  48 */         Reference other = (Reference)obj;
/*  49 */         return (other.fileId == this.fileId) && (other.version == this.version);
/*     */       }
/*  51 */       return super.equals(obj);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */     public int hashCode()
/*     */     {
/*  58 */       return this.fileId ^ this.version;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public PatchManifest()
/*     */   {
/*  69 */     this.references = new HashMap();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void addReference(int fileId, int version, int numBytes)
/*     */   {
/*  81 */     assert (fileId > 0) : "File id must be > 0";
/*  82 */     assert (version > 0) : "Version must be > 0";
/*  83 */     assert (numBytes > 0) : "References cannot refer to 0 bytes";
/*     */     
/*  85 */     Reference ref = new Reference(fileId, version);
/*     */     
/*  87 */     long totalBytesSoFar = numBytes;
/*     */     
/*  89 */     Long currentTotal = (Long)this.references.remove(ref);
/*     */     
/*  91 */     if (currentTotal != null) {
/*  92 */       totalBytesSoFar += currentTotal.longValue();
/*     */     }
/*     */     
/*  95 */     this.references.put(ref, Long.valueOf(totalBytesSoFar));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void writeTo(OutputStream os)
/*     */     throws IOException
/*     */   {
/* 108 */     BinaryWriterHelper helper = new BinaryWriterHelper(os);
/*     */     
/* 110 */     os.write("OPMANI".getBytes());
/* 111 */     helper.writeShort((short)0);
/* 112 */     helper.writeInt(this.references.size());
/*     */     
/* 114 */     for (Map.Entry<Reference, Long> entry : this.references.entrySet())
/*     */     {
/* 116 */       helper.writeInt(((Reference)entry.getKey()).fileId);
/* 117 */       helper.writeInt(((Reference)entry.getKey()).version);
/* 118 */       helper.writeLong(((Long)entry.getValue()).longValue());
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/octosync/PatchManifest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */